package com.myapp.api.mapper;

import com.myapp.api.entity.StudentCourse;
import com.myapp.api.entity.StudentCourseKey;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface StudentCourseMapper {
    @Delete({
        "delete from student_course",
        "where id = #{id,jdbcType=INTEGER}",
            "and Sid = #{sid,jdbcType=VARCHAR}",
            "and Cid = #{cid,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(StudentCourseKey key);

    @Insert({
        "insert into student_course (id, Sid, ",
        "Cid, Score, SecondScore, ",
        "CreateTime, UpdateTime)",
            "values (#{id,jdbcType=INTEGER}, #{sid,jdbcType=VARCHAR}, ",
            "#{cid,jdbcType=VARCHAR}, #{score,jdbcType=DOUBLE}, #{secondscore,jdbcType=DOUBLE}, ",
        "#{createtime,jdbcType=TIMESTAMP}, #{updatetime,jdbcType=TIMESTAMP})"
    })
    int insert(StudentCourse record);

    @InsertProvider(type=StudentCourseSqlProvider.class, method="insertSelective")
    int insertSelective(StudentCourse record);

    @Select({
        "select",
        "id, Sid, Cid, Score, SecondScore, CreateTime, UpdateTime",
        "from student_course",
        "where id = #{id,jdbcType=INTEGER}",
            "and Sid = #{sid,jdbcType=VARCHAR}",
            "and Cid = #{cid,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Sid", property = "sid", jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column = "Cid", property = "cid", jdbcType = JdbcType.VARCHAR, id = true),
        @Result(column="Score", property="score", jdbcType=JdbcType.DOUBLE),
        @Result(column="SecondScore", property="secondscore", jdbcType=JdbcType.DOUBLE),
        @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="UpdateTime", property="updatetime", jdbcType=JdbcType.TIMESTAMP)
    })
    StudentCourse selectByPrimaryKey(StudentCourseKey key);

    @UpdateProvider(type=StudentCourseSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(StudentCourse record);

    @Update({
        "update student_course",
        "set Score = #{score,jdbcType=DOUBLE},",
          "SecondScore = #{secondscore,jdbcType=DOUBLE},",
          "CreateTime = #{createtime,jdbcType=TIMESTAMP},",
          "UpdateTime = #{updatetime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=INTEGER}",
            "and Sid = #{sid,jdbcType=VARCHAR}",
            "and Cid = #{cid,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(StudentCourse record);

    @Select({
            "select",
            "id, Sid, Cid, Score, SecondScore, CreateTime, UpdateTime",
            "from student_course"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Sid", property = "sid", jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column = "Cid", property = "cid", jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column="Score", property="score", jdbcType=JdbcType.DOUBLE),
            @Result(column="SecondScore", property="secondscore", jdbcType=JdbcType.DOUBLE),
            @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="UpdateTime", property="updatetime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<StudentCourse> getStudentCourses();
}